classdef MyComplex % class definition
    properties
        Real % 实部
        Imaginary % 虚部
		Dream % dream部
    end
    
    methods
        % 构造函数
        function obj = MyComplex(realPart, imaginaryPart, dreamPart)
            if nargin > 0
                obj.Real = realPart;
                obj.Imaginary = imaginaryPart;
				obj.Dream = dreamPart;
            else
                obj.Real = 0;
                obj.Imaginary = 0;
				obj.Dream = 0;
            end
        end
        
        % 加法运算
        function result = plus(obj1, obj2)
            result = MyComplex(obj1.Real + obj2.Real, obj1.Imaginary + obj2.Imaginary);
        end
        
        % 减法运算
        function result = minus(obj1, obj2)
            result = MyComplex(obj1.Real - obj2.Real, obj1.Imaginary - obj2.Imaginary);
        end
        
        % 乘法运算
        function result = mtimes(obj1, obj2)
            realPart = obj1.Real * obj2.Real - obj1.Imaginary * obj2.Imaginary;
            imaginaryPart = obj1.Real * obj2.Imaginary + obj1.Imaginary * obj2.Real;
            result = MyComplex(realPart, imaginaryPart);
        end
        
        % 复数模
        function result = abs(obj)
            result = sqrt(obj.Real^2 + obj.Imaginary^2);
        end
        
        % 复数相位角
        function result = angle(obj)
            result = atan2(obj.Imaginary, obj.Real);
        end
        
        % 显示复数的字符串表示
        function display(obj)
            fprintf('%g + %gi\n', obj.Real, obj.Imaginary);
        end
    end
end
